<template>
    <el-dialog
        title="激活向导"
        :visible.sync="dialogVisible"
        :close-on-click-modal="false"
        :cclose-on-press-escape="false"
        @closed="close"
        @open="open"
        width="600px">
        <el-form :model="formdata" label-width="120px" ref="addform"  :rules="rules">
            <el-form-item label="">
                <el-button v-if="!isDisabled" type="primary" @click="save" style="width:330px">激 活</el-button>
                <el-button v-else disabled type="warning" @click="save" style="width:330px">已 激 活</el-button>
            </el-form-item>
            <el-form-item label="上级代码：" prop="bDeptNo">
                <el-input :disabled="hasValue" type="text" style="width:330px" v-model.trim="formdata.bDeptNo" placeholder="请输入上级代码"></el-input>
            </el-form-item>
            <el-form-item label="学段：" prop="bMSN">
                <el-select :disabled="hasValue" style="width:330px" v-model="formdata.bMSN" placeholder="请选择学段">
                    <el-option :label="item.Code_Name" :value="item.Code_No" v-for="item in SECTION" :key="item.Code_No"></el-option>
                </el-select>
                <!-- <el-input :disabled="hasValue" type="text" style="width:330px" v-model.trim="formdata.bMSN" placeholder="请输入上级代码"></el-input> -->
            </el-form-item>
            <el-form-item label="机构代码：">
                <span>{{formdata.bUserName}}</span>
            </el-form-item>
            <el-form-item v-if="hasValue" label="激活时间：">
                <span>{{info.ActivationTime}}</span>
            </el-form-item>
            <el-form-item v-if="hasValue" label="有效期至：">
                <span>{{info.TerminationTerm}}</span>
            </el-form-item>
            <el-form-item v-if="hasValue" label="剩余天数：">
                <span>{{info.ts}}</span>
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <!-- <el-button type="primary" @click="save">完 成</el-button> -->
        </div>
    </el-dialog>
</template>
<script>
import {regedit} from '@/api/index.js'
export default {
    data() {
        return {
            dialogVisible:false,
            formdata:{
                bDeptNo:'',
                bUserName:'',
                bMSN:''
            },
            rules: {
                bDeptNo:[
                    {required:true,message:'上级代码不能为空！',trigger: 'blur'}
                ],
                bMSN:[
                    {required:true,message:'请选择学段！',trigger: 'change'}
                ]
            }
        }
    },
    props:{
        isDisabled:{
            type:Boolean,
            default:false
        },
        hasValue:{
            type:Boolean,
            default:false
        },
        info:{
            type:Object,
            default:function() {
                return {}
            }
        },
        bDeptNo:{
            type:String,
            default:''
        },
        bUserName:{
            type:String,
            default:''
        },
        bMSN:{
            type:String,
            default:''
        },
        SECTION:{
            type:Array,
            default:function(){
                return []
            }
        }
    },
    methods:{
        open() {
            this.formdata.bDeptNo = this.bDeptNo || this.info.DeptNo;
            this.formdata.bUserName = this.bUserName || this.info.UserName;
            this.formdata.bMSN = this.bMSN || this.info.MSN;
        },
        save(){
            this.$refs.addform.validate((valid) => {
                if(valid) {
                    regedit({...this.formdata}).then((res) => {
                        if(res) {
                            if(res.code == 200 ){
                                this.$util.tipsMsg('success',res.message);
                                setTimeout(() => {
                                    this.$router.push({path:'/home'})
                                },2000)
                            } else {
                                this.$util.tipsMsg('error',res.message);
                            }
                        }
                    }).catch((err) => {
                        
                    })
                }
                
            })
            
        },
        close(){
            this.$refs.addform.resetFields();
        }
    }
}
</script>
<style lang="less" scoped>

</style>
